package net.kong.sns.rest.client.model;

import java.util.Map;
import java.util.Set;

/**
 * @author <a href="mailto:lanhuai@gmail.com">Ning Yubin</a>
 * @version $Id: UserAuthImpl.java,v 1.2 2009/07/31 09:24:41 ningyubin Exp $
 */
public class UserAuthImpl extends AbstractJsonAppObject implements UserAuth {
    private long userId;
    private boolean auth;

    public long getUserId() {
        return userId;
    }

    public boolean isAuth() {
        return auth;
    }

    @Override
    protected void processJsonObject(Map<String, Object> stringObjectMap) {
        if (stringObjectMap != null) {
            Set<String> fields = getInitializedFields();
            for (String fieldName : fields) {
                Object o = stringObjectMap.get(fieldName);
                if (o != null) {
                    if (fieldName.equals(UserAuth.Field.USER_ID.toString())) {
                        this.userId = (Long) o;
                    } else if (fieldName.equals(UserAuth.Field.IS_AUTH.toString())) {
                        String s = (String) o;
                        this.auth = s.trim().equals("1");
                    }
                }
            }
        }
    }
}
